﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WMS.BLL;
using WMS.Model;
using System.Data;
using System.Text;
/// <summary>
///WarehouseMngr 的摘要说明
/// </summary>
public class WarehouseMngr:HandlerBase
{
    WhsMngrManage manage = new WhsMngrManage();

    #region 仓库维护信息
    //查询仓库信息
    public void GetAllWhsInfo()
    {
        string whNo = _request["whNo"];
        DataTable dt = new DataTable();
        WhsModel model = new WhsModel();
        model.SupId = _user.CII;
        model.WhsWhs = whNo;
        StringBuilder json = new StringBuilder();
        dt = manage.GetAllWhsInfo(model);
        JsonTransfer js = new JsonTransfer();
       // js.Add("total", dt.Rows.Count);
        js.Add("rows",dt);
        _response.Write(js);
    }

    public void GetWhsInfoByNo()
    {
        string no = _request["no"];
        WhsModel model = new WhsModel();
        model.WhsWhs = no;
        model.SupId = _user.CII;
        DataTable  dt = new DataTable();
        dt = manage.GetAllWhsInfo(model);
        JsonTransfer js = new JsonTransfer();
        model.WhsWhs = dt.Rows[0]["WHS_WHS"].ToString();
        model.WhsDesc =dt.Rows[0]["WHS_DESN"].ToString();
        js.Add("list", model);
        _response.Write(js);
    }

    //删除仓库信息
    public void DelWhsByID()
    {
        string ids = _request["ids"];
        int rows = manage.DelWhsByIds(ids);
        JsonTransfer jf = new JsonTransfer();
        if (rows > 0)
            jf.Add("success", "ok", false);
        else
            jf.SetError("删除失败");
        _response.Write(jf);
    }

    //增加仓库信息
    public void AddWhs()
    {
        JsonTransfer jf = new JsonTransfer();
        WhsModel model = new WhsModel();
        model.WhsWhs = _request.Form["whsNoTxt"];
        model.WhsDesc = _request.Form["whsDescTxt"];
        model.WhsPno = _user.CII;
        model.SupId = _user.CII;
        model.CtMan = _user.UserName;
        //model.Wlc = new WlcModel();
        int rows = manage.AddWhs(model);
        if (rows > 0)
            jf.Add("success", "ok", false);
        else
            jf.SetError("删除失败");
        _response.Write(jf);

    }

    //修改仓库信息
    public void ModifyWhs()
    {
        //string strModel = _request["whsModule"];
        JsonTransfer jf = new JsonTransfer();
        WhsModel model = new WhsModel();
        model.WhsWhs = _request["no"];
        model.WhsDesc = _request.Form["whsDescTxt"];
        model.SupId = _user.CII;
        model.WhsPno = _user.CII;
        model.CtMan = _user.UserName;
        int rows = manage.MidifyWhs(model);
        if (rows > 0)
            jf.Add("success", "ok", false);
        else
            jf.SetError("删除失败");
        _response.Write(jf);
    }
    #endregion

    #region 仓库权限设定
    public void GetWhsLst()
    {
        string supId = _user.CII;
        StockInManage stockMngr = new StockInManage();
        DataTable dt = stockMngr.GetWHSInfoBysupId(supId);
        JsonTransfer jt = new JsonTransfer();
        jt.Add("list", dt);
        _response.Write(jt);
    }

    public void GetUserRole()
    {
        string supId = _user.CII;
        DataTable dt = manage.GetUserRoles(supId);
        JsonTransfer js = new JsonTransfer();
        js.Add("list", dt);
        _response.Write(js);
    }

    public void GetWhsRoleByRoleId()
    {
       // StockInManage stockMngr = new StockInManage();
        string r = _request["roleId"];
        string supId = _user.CII;
        JsonTransfer jf = new JsonTransfer();
        if(string.IsNullOrEmpty(r))
             jf.SetError("请选择需设定的权限");
        else
        {
            DataTable roles = manage.GetWhsRoleByRoleId(r, supId);
            jf.Add("list", roles);
        }
        _response.Write(jf);
    }

    public void SetWhsPermiss()
    {
        string uid = _user.ID;
        WMS.Model.OrderOnline_Role role = new WMS.Model.OrderOnline_Role();
        string rName = _request["rname"];
        string rId = _request["rid"];
        string whss = _request["whs"];
        string uName = _user.UserName;
        string supId = _user.CII;
        role.RoleName = rName;
        role.Id = rId;
        JsonTransfer jf = new JsonTransfer();
        if (manage.SetWhsPermiss(role, whss, uName, supId) > 0)
        {
            jf.Add("success", "设置保存成功");
        }
        else
        {
            jf.SetError("该设置信息已经存在，设置保存失败");
        }
        _response.Write(jf);
    }

    #endregion
}